<?php
use_stylesheet('data/main.css');
use_javascript('data/main.js');
use_javascript('publication/publicationrefresh.js');

//require_once dirname(__FILE__).'\..\..\..\lib\BibTex.php';
?>

<script type="text/javascript">
    $(document).ready(function() {

        if ($("#saved_not").html() != null) {
            $("#compelete_not").hide();

            setTimeout(function(){
                $("#saved_not").fadeOut('slow');
            }, 1000)

            setTimeout(function(){
                $("#compelete_not").fadeIn(2000);
            }, 2000);
        }

        $(".edit").button({
             icons: {
                primary: "ui-icon-pencil"
            }
        });

        $(".edit").button({
             icons: {
                primary: "ui-icon-pencil"
            }
        });

        $("#lnkAddUser").button({
             icons: {
                primary: "ui-icon-plus"
            }
        });
        
    });
</script>

<table width="977px">
    <tr>
        <td>
            <div class="datacontent">
                <?php if(!empty($research)): ?>
                    <?php include_component('approval', 'researchStatus', array('researchid' => $research->id)) ?>
                <?php endif;?>

                <?php if(isset($success) && $success): ?>
                    <p id="saved_not" class="ui-state-highlight notification">Data saved.</p>
                <?php endif;?>

                <h1 class="data">Document Information</h1>

                <a class="edit" style="font-size: 80%" title="Edit Observation" href="<?php echo url_for('data/editResearch?id='.$research->id) ?>" >
                    <span>Edit</span>
                </a>

                <div class="subheader research-sub">
                    Title, Citation, and Abstract
                </div>

                <p><?php echo $research->title ?></p>

                <p>
                    <?php if (!empty($genCitation)): ?>
                        <?php echo $sf_data->getRaw('genCitation') ?>
                        <span style="font-size: 85%">(Download citation as <a href="<?php echo url_for('data/getBibtex?id='.$research->id) ?>">BibTeX</a>)</span>
                    <?php endif; ?>
                </p>

                <script type="text/javascript">
        //            var entryvalues = new Object;
                    <?php
        //            $entry = $bibtex->data[0];
        //            $type = $entry['type'];
        //
        //            while($entry->valid()):
        //                $key = $entry->key();
        //                if ($key == 'author') {
        //                    $author = "";
        //                    foreach ($entry->current() as $au) {
        //                        $author .= $au['first'] . ' ' . $au['last'] . ' ';
        //                    }
        //                    $value = $author;
        //                } else {
        //                    $value = $entry->current();
        //                }
                    ?>
        //                entryvalues.<?php //echo $key; ?> = "<?php //echo $value; ?>";

                    <?php
        //                $entry->next();
        //            endwhile;
                    ?>

                    /* <![CDATA[ */
        //            EBcitation = entryvalues;
        //            EBversion  = "1.0";
        //            document.write(unescape("%3Cscript src='http://cdn.easybib.com/citethis/"+EBversion+"/widget_mini.js' type='text/javascript'%3E%3C/script%3E"));
                    /* ]]> */
                </script>

                <p><?php echo $research->abstract; ?></p>

                <div class="subheader research-sub">
                    Published or Unpublished
                </div>

               <p><?php
                   foreach (Types::$RESEARCH_STATUS as $status => $id) {
                       if ($research->researchstatustyperefid == $id)
                           echo ucwords(strtolower($status));
                   }
                   ?> research.


                    <?php if (!empty($research->researchpaperfilename)): ?>
                    Download paper
                        <a href="<?php echo url_for('data/downloadResearchPaper?id='.$research->id) ?>">
                                <?php echo $research->researchpaperfilename ?></a>
                    <?php else: ?>

                    <?php endif; ?>
                </p>

                <?php echo $research->researchpaperurl; ?>

                <div class="subheader research-sub">
                    Remarks
                </div>

                <p><?php echo $research->remarks; ?></p>
            </div>
        </td>
        <td width="348px">
            <div class="obs-area">
        <?php if(!empty($research)): ?>
            <p id="compelete_not" class="highlight">Complete your observation data below.</p>
            <div class="subheader">Observation
                <a class="edit" title="Edit Observation" href="<?php echo url_for('data/showObservation?id='. $research->id) ?>">
                    <span>Edit</span></a>
            </div>
            <div class="subheader">Map Overlay
                <a class="edit" title="Map Overlay" href="<?php echo url_for('data/showOverlay?id='. $research->id) ?>">
                    <span>Edit</span></a>
            </div>
            <div class="subheader">Collaborator
                <a id="lnkAddUser" title="Add collaborator" onclick="return loadNewCollaborativeUserDialog(20,400,false,'dlgAddUser', <?php echo $research->id; ?>, 'txtRid');">
                    <span>Add User</span>
                </a>
            </div>
            <?php $totalCollaborators = $research->getResearchgroup()->count(); $tempIndex = 0; ?>
            <?php foreach ($research->getCollaboratorList(Types::$COLLABORATION_REQUEST_STATUS[Types::$COLLABORATION_REQUEST_STATUS_REJECTED], true) as $researchGroup): ?>
                <?php $tempIndex++; ?>
                    <span>
                    <?php echo Entity::GetEntity( $researchGroup->getCollaborativeentityid())->getFullname(); ?>

                    <?php if(($research->getEntityid() == $sf_user->getAttribute('currentuser')->getId()) || ($researchGroup->getCollaborativeentityid() == $sf_user->getAttribute('currentuser')->getId())): ?>
                        <a class="clickable" id="lnkRemoveCollaborativeUser" onclick="return removeCollaborativeUser(<?php echo $researchGroup->getCollaborativeentityid(); ?>, <?php echo $research->getId(); ?>);">
                            (Remove)
                        </a>
                    <?php endif; ?>

                    <?php if($tempIndex < $totalCollaborators): ?>
                        <label>, </label>
                    <?php endif; ?>
                    </span>
            <?php endforeach; ?>
            <input id="txtRid" type="hidden"/>
            <div id="boxes">
                <div id="dlgAddUser" class="window ui-dialog ui-widget ui-widget-content ui-corner-all">
                    <div class="ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix">
                        <span class="ui-dialog-title" id="ui-dialog-title-observation-form-dialog">Invite collaborator</span>
                        <a onclick="javascript:$('.window').hide()" class="ui-dialog-titlebar-close ui-corner-all clickable" role="button">
                            <span class="ui-icon ui-icon-closethick">close</span>
                        </a>
                    </div>
                    <table cellpadding="0" cellspacing="0" width="100%" style="padding: 10px; font-size: 90%">
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr id="trErrorMessage">
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="left">
                                <span>User Name</span>
                            </td>
                            <td align="right">
                                <input style="width: 290px; padding: 3px;" type="text" id="txtMailTo" onclick="javascript:LoadUserList();" class="ui-autocomplete-input required text ui-widget-content ui-corner-all"/>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="center">

                            </td>
                            <td align="right">
                                <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="lnkAddUser" onclick="return addCollaborativeUser(document.getElementById('txtRid').value, $('#txtMailTo').val(), false);">
                                    <span class="ui-button-text">Add User</span>
                                </button>
                                <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" onclick="javascript:$('.window').hide();">
                                    <span class="ui-button-text">Cancel</span>
                                </button>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        <?php endif; ?>

    </div>
        </td>
    </tr>
</table>